<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="utf-8">
    <meta content="en" name="language">
	<title>GraphicsMagick Perl API -- PerlMagick</title>
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
	<link media="screen" href="docutils-articles.css" type="text/css" rel="stylesheet">

</head>

<body>

<div class="banner">
<img src="images/gm-107x76.png" alt="GraphicMagick logo" width="107" height="76" />
<span class="title">GraphicsMagick</span>
<form action="http://www.google.com/search">
  <input type="hidden" name="domains" value="www.graphicsmagick.org" />
  <input type="hidden" name="sitesearch" value="www.graphicsmagick.org" />
<span class="nowrap"><input type="text" name="q" size="25" maxlength="255" />&nbsp;<input type="submit" name="sa" value="Search" /></span>
</form>
</div>


<div class="navmenu">
<ul>
  <li><a href="index.html">Home</a></li>
  <li><a href="project.html">Project</a></li>
  <li><a href="download.html">Download</a></li>
  <li><a href="README.html">Install</a></li>
  <li><a href="Hg.html">Source</a></li>
  <li><a href="NEWS.html">News</a> </li>
  <li><a href="utilities.html">Utilities</a></li>
  <li><a href="programming.html">Programming</a></li>
  <li><a href="reference.html">Reference</a></li>
</ul>
</div>

<main id="graphicsmagick-perl-api-perlmagick">
<h1 class="title">GraphicsMagick Perl API -- PerlMagick</h1>
<!-- -*- mode: rst -*- -->
<!-- This text is in reStucturedText format, so it may look a bit odd. -->
<!-- See http://docutils.sourceforge.net/rst.html for details. -->
<div class="contents local topic" id="contents">
<ul class="simple">
<li><p><a class="reference internal" href="#introduction" id="id1">Introduction</a></p></li>
<li><p><a class="reference internal" href="#installation" id="id2">Installation</a></p>
<ul>
<li><p><a class="reference internal" href="#unix" id="id3">UNIX</a></p></li>
<li><p><a class="reference internal" href="#windows-xp-windows-12" id="id4">Windows XP - Windows 12</a></p></li>
<li><p><a class="reference internal" href="#running-the-regression-tests" id="id5">Running the Regression Tests</a></p></li>
</ul>
</li>
<li><p><a class="reference internal" href="#overview" id="id6">Overview</a></p></li>
<li><p><a class="reference internal" href="#example-script" id="id7">Example Script</a></p></li>
<li><p><a class="reference internal" href="#read-or-write-an-image" id="id8">Read or Write an Image</a></p></li>
<li><p><a class="reference internal" href="#manipulate-an-image" id="id9">Manipulate an Image</a></p></li>
<li><p><a class="reference internal" href="#set-an-image-attribute" id="id10">Set an Image Attribute</a></p></li>
<li><p><a class="reference internal" href="#get-an-image-attribute" id="id11">Get an Image Attribute</a></p></li>
<li><p><a class="reference internal" href="#create-an-image-montage" id="id12">Create an Image Montage</a></p></li>
<li><p><a class="reference internal" href="#working-with-blobs" id="id13">Working with Blobs</a></p></li>
<li><p><a class="reference internal" href="#miscellaneous-methods" id="id14">Miscellaneous Methods</a></p></li>
<li><p><a class="reference internal" href="#handling-errors" id="id15">Handling Errors</a></p></li>
</ul>
</div>
<section id="introduction">
<h1><a class="toc-backref" href="#id1">Introduction</a></h1>
<p>PerlMagick is an objected-oriented Perl interface to GraphicsMagick. Use
the module to read, manipulate, or write an image or image sequence from
within a Perl script. This makes it very suitable for Web CGI scripts.
You must have GraphicsMagick 1.0.0 or above and Perl version 5.005_02 or
greater installed on your system for either of these utilities to work.
There are a number of useful scripts available to show you the value of
PerlMagick. The PerlMagick demo directory provides a number of sample
demos.</p>
</section>
<section id="installation">
<h1><a class="toc-backref" href="#id2">Installation</a></h1>
<section id="unix">
<h2><a class="toc-backref" href="#id3">UNIX</a></h2>
<p>PerlMagick is installed by default by installing GraphicsMagick.
Installing PerlMagick as a subordinate package of GraphicsMagick is the
best way to avoid problems.</p>
<p>For Unix, you typically need to be root to install the software. There
are ways around this. Consult the Perl manual pages for more information.</p>
</section>
<section id="windows-xp-windows-12">
<h2><a class="toc-backref" href="#id4">Windows XP - Windows 12</a></h2>
<p>[ These procedures have not been exercised for some time ]</p>
<p>After GraphicsMagick has been compiled from the GraphicsMagick Windows
source distribution using Microsoft Visual C++, PerlMagick may be
manually built and installed by opening a CLI window and performing the
following steps:</p>
<pre class="literal-block">cd PerlMagick
copy Makefile.nt Makefile.PL
perl Makefile.PL
nmake
nmake install</pre>
<p>See the PerlMagick Windows HowTo page for further installation
instructions.</p>
</section>
<section id="running-the-regression-tests">
<h2><a class="toc-backref" href="#id5">Running the Regression Tests</a></h2>
<p>To verify a correct installation, type:</p>
<pre class="literal-block">make test</pre>
<p>Use nmake test under Windows. There are a few demonstration scripts
available to exercise many of the functions PerlMagick can perform. Type</p>
<pre class="literal-block">cd demo
make</pre>
<p>You are now ready to utilize the PerlMagick methods from within your Perl
scripts.</p>
</section>
</section>
<section id="overview">
<h1><a class="toc-backref" href="#id6">Overview</a></h1>
<p>Any script that wants to use PerlMagick methods must first define the
methods within its namespace and instantiate an image object. Do this
with</p>
<pre class="literal-block">use Graphics::Magick;
$image=Graphics::Magick-&gt;new;</pre>
<p>Note that this differs from the ImageMagick version of PerlMagick which
uses the namespace Image::Magick. Any PerlMagick code written for the
ImageMagick version of PerlMagick requires a global substitution of
Image::Magick to Graphics::Magick in order to work with the
GraphicsMagick version.</p>
<p>The new() method takes the same parameters as SetAttribute . For example:</p>
<pre class="literal-block">$image=Graphics::Magick-&gt;new(size=&gt;'384x256');</pre>
<p>Next you will want to read an image or image sequence, manipulate it, and
then display or write it. The input and output methods for PerlMagick are
defined in Read or Write an Image. See Set an Image Attribute for methods
that affect the way an image is read or written. Refer to Manipulate an
Image for a list of methods to transform an image. Get an Image Attribute
describes how to retrieve an attribute for an image. Refer to Create an
Image Montage for details about tiling your images as thumbnails on a
background. Finally, some methods do not neatly fit into any of the
categories just mentioned. Review Miscellaneous Methods for a list of
these methods.</p>
<p>Once you are finished with a PerlMagick object you should consider
destroying it. Each image in an image sequence is stored in either
virtual memory or as a file in the system's temporary file directory.
This can potentially add up to megabytes of memory or disk. Upon
destroying a PerlMagick object, the memory is returned for use by other
Perl methods. The recommended way to destroy an object is with undef</p>
<pre class="literal-block">undef $image;</pre>
<p>To delete all the images but retain the Graphics::Magick object use</p>
<pre class="literal-block">&#64;$image = ();</pre>
<p>and finally, to delete a single image from a multi-image sequence, use</p>
<pre class="literal-block">undef $image-&gt;[x];</pre>
<p>The next section illustrates how to use various PerlMagick methods to
manipulate an image sequence.</p>
<p>Some of the PerlMagick methods require external programs such as
Ghostscript. This may require an explicit path in your PATH environment
variable to work properly. For example,</p>
<pre class="literal-block">$ENV{PATH}='/bin:/usr/bin:/usr/local/bin';</pre>
</section>
<section id="example-script">
<h1><a class="toc-backref" href="#id7">Example Script</a></h1>
<p>Here is an example script to get you started:</p>
<pre class="literal-block">#!/usr/local/bin/perl
use Graphics::Magick;
my($image, $status);
$image = Graphics::Magick-&gt;new;
$status = $image-&gt;Read('girl.png', 'logo.png', 'rose.png');
warn &quot;$status&quot; if &quot;$status&quot;;
$status = $image-&gt;Crop(geometry=&gt;'100x100+100+100');
warn &quot;$status&quot; if &quot;$status&quot;;
$status = $image-&gt;Write('x.gif');
warn &quot;$status&quot; if &quot;$status&quot;;</pre>
<p>The script reads three images, crops them, and writes a single image as a
GIF animation sequence. In many cases you may want to access individual
images of a sequence. The next example illustrates how this is done:</p>
<pre class="literal-block">#!/usr/local/bin/perl
use Graphics::Magick;
my($image, $p, $q);
$image = new Graphics::Magick;
$image-&gt;Read('x1.png');
$image-&gt;Read('j*.jpg');
$image-&gt;Read('k.miff[1, 5, 3]');
$image-&gt;Contrast();
for ($x = 0; $image-&gt;[x]; $x++)
{
  $image-&gt;[x]-&gt;Frame('100x200') if $image-&gt;[x]-&gt;Get('magick') eq 'GIF';
  undef $image-&gt;[x] if $image-&gt;[x]-&gt;Get('columns') &lt; 100;
}
$p = $image-&gt;[1];
$p-&gt;Draw(stroke=&gt;'red', primitive=&gt;'rectangle', points=&gt;'20,20 100,100');
$q = $p-&gt;Montage();
undef $image;
$q-&gt;Write('x.miff');</pre>
<p>Suppose you want to start out with a 100 by 100 pixel white canvas with a
red pixel in the center. Try</p>
<pre class="literal-block">$image = Graphics::Magick-&gt;new;
$image-&gt;Set(size=&gt;'100x100');
$image-&gt;ReadImage('xc:white');
$image-&gt;Set('pixel[49,49]'=&gt;'red');</pre>
<p>Or suppose you want to convert your color image to grayscale:</p>
<pre class="literal-block">$image-&gt;Quantize(colorspace=&gt;'gray');</pre>
<p>Here we annotate an image with a Taipai TrueType font:</p>
<pre class="literal-block">$text = 'Works like magick!';
$image-&gt;Annotate(font=&gt;'kai.ttf', pointsize=&gt;40, fill=&gt;'green', text=&gt;$text);</pre>
<p>Other clever things you can do with a PerlMagick objects include</p>
<pre class="literal-block">$i = $#$p&quot;+1&quot;; # return the number of images associated with object p
push(&#64;$q, &#64;$p); # push the images from object p onto object q
&#64;$p = (); # delete the images but not the object p
$p-&gt;Convolve([1, 2, 1, 2, 4, 2, 1, 2, 1]); # 3x3 Gaussian kernel</pre>
</section>
<section id="read-or-write-an-image">
<h1><a class="toc-backref" href="#id8">Read or Write an Image</a></h1>
<p>Use the methods listed below to either read, write, or display an image
or image sequence.</p>
<table>
<caption>Read or Write Methods</caption>
<colgroup>
<col style="width: 10%" />
<col style="width: 19%" />
<col style="width: 27%" />
<col style="width: 44%" />
</colgroup>
<tbody>
<tr><td><p>Method</p></td>
<td><p>Parameters</p></td>
<td><p>Return Value</p></td>
<td><p>Description</p></td>
</tr>
<tr><td><p>Read</p></td>
<td><p>one or more
filenames</p></td>
<td><p>the number of
images read</p></td>
<td><p>read an image or image sequence</p></td>
</tr>
<tr><td><p>Write</p></td>
<td><p>filename</p></td>
<td><p>the number of
images written</p></td>
<td><p>write an image or image
sequence</p></td>
</tr>
<tr><td><p>Display</p></td>
<td><p>server name</p></td>
<td><p>the number of
images displayed</p></td>
<td><p>display the image or image
sequence to an X server</p></td>
</tr>
<tr><td><p>Animate</p></td>
<td><p>server name</p></td>
<td><p>the number of
images animated</p></td>
<td><p>animate image sequence to an X
server</p></td>
</tr>
</tbody>
</table>
<p>For convenience, methods Write(), Display(), and Animate() can take any
parameter that SetAttribute knows about. For example,</p>
<pre class="literal-block">$image-&gt;Write(filename=&gt;'image.png', compression=&gt;'None');</pre>
<p>Use - as the filename to method Read() to read from standard in or to
method Write() to write to standard out:</p>
<pre class="literal-block">binmode STDOUT;
$image-&gt;Write('png:-');</pre>
<p>To read an image from a disk file, use:</p>
<blockquote>
<p>$image = Graphics::Magick-&gt;new;
$filename = 'test.gif';
$status = $image-&gt;Read ($filename);</p>
</blockquote>
<p>and to write the image back to the disk file, use:</p>
<pre class="literal-block">$status = $image-&gt;Write($filename);</pre>
<p>To read an image in the GIF format from a PERL filehandle, use:</p>
<pre class="literal-block">$image = Graphics::Magick-&gt;new;
open(IMAGE, 'image.gif');
$status = $image-&gt;Read(file=&gt;\*IMAGE);
close(IMAGE);</pre>
<p>To write an image in the PNG format to a PERL filehandle, use:</p>
<pre class="literal-block">$filename = &quot;image.png&quot;;
open(IMAGE, &quot;&gt;$filename&quot;);
$status = $image-&gt;Write(file=&gt;\*IMAGE, filename=&gt;$filename);
close(IMAGE);</pre>
<p>If %0Nd appears in the filename, it is interpreted as a printf format
specification and the specification is replaced with the specified
decimal encoding of the scene number. For example,</p>
<pre class="literal-block">image%03d.miff</pre>
<p>converts files image000.miff, image001.miff, etc.</p>
<p>You can optionally add Image to any method name. For example, ReadImage()
is an alias for method Read().</p>
<p>To set encoder parameters when saving a file use AddDefinition($magick, $key,
$value); this returns 0 on success or 1 on failure. A comma-delimited list of
parameters can also be set using AddDefinition($values); this returns 0 on
success or 1 on failure. To remove parameters use RemoveDefinitions($keys)
(comma-delimited; the special key * can be used to remove all definitions);
this returns 1 if the specified keys were present and removed, 0 otherwise.
To get the current value of a parameter use AccessDefinition($magick, $key);
note that if no value was explicitly set then undef is returned. These are
equivalent to using the commandline gm utility's -define option. For example,
to save a lossless WebP image one can use:</p>
<blockquote>
<p>$image-&gt;AddDefinition('webp', 'lossless', 'TRUE');
$image-&gt;Write(filename=&amp;gt;'webp:output.webp');</p>
</blockquote>
<p>or</p>
<blockquote>
<p>$image-&gt;AddDefinitions('webp:lossless=TRUE');
$image-&gt;Write(filename=&amp;gt;'webp:output.webp');</p>
</blockquote>
</section>
<section id="manipulate-an-image">
<h1><a class="toc-backref" href="#id9">Manipulate an Image</a></h1>
<p>Once you create an image with, for example, method ReadImage() you may want
to operate on it. Below is a list of all the image manipulations methods
available to you with PerlMagick. There are examples of select PerlMagick
methods. Here is an example call to an image manipulation method:</p>
<pre class="literal-block">$image-&gt;Crop(geometry=&gt;'100x100&quot;+1&quot;0+20');
$image-&gt;[x]-&gt;Frame(&quot;100x200&quot;);</pre>
<p>Image method parameters are often redundant. For example, a 'geometry'
string parameter (e.g. 800x600+10+20) is equivalent to the explicit use of
width, height, x, and y, parameters.</p>
<p>The following image manipulation methods are available:</p>
<table>
<caption>Image Manipulation Methods</caption>
<colgroup>
<col style="width: 24%" />
<col style="width: 46%" />
<col style="width: 30%" />
</colgroup>
<tbody>
<tr><td><p>Method</p></td>
<td><p>Parameters</p></td>
<td><p>Description</p></td>
</tr>
<tr><td><p>AdaptiveThreshold</p></td>
<td><p>geometry=&gt;geometry, width=&gt;
integer, height=&gt; integer, offset
=&gt;integer</p></td>
<td><p>Local adaptive
thresholding. Width
and height specify
the size of the local
region while offset
specifies the amount
to subtract from the
average of the
region.</p></td>
</tr>
<tr><td><p>AddNoise</p></td>
<td><p>noise=&gt;{Uniform, Gaussian,
Multiplicative, Impulse,
Laplacian, Poisson, Random}</p></td>
<td><p>Add noise to an image
across the red,
green, and blue,
channels. Set the
image colorspace to
GRAY to obtain
intensity noise.</p></td>
</tr>
<tr><td><p>AffineTransform</p></td>
<td><p>affine=&gt;array of float values,
translate=&gt;float, float, scale=&gt;
float, float, rotate=&gt;float,
skewX=&gt;float, skewY=&gt;float</p></td>
<td><p>Affine transform
image</p></td>
</tr>
<tr><td><p>Annotate</p></td>
<td><p>text=&gt;string, font=&gt;string,
family=&gt;string, style=&gt;{Normal,
Italic, Oblique, Any}, stretch=&gt;
{Normal, UltraCondensed,
ExtraCondensed, Condensed,
SemiCondensed, SemiExpanded,
Expanded, ExtraExpanded,
UltraExpanded}, weight=&gt;integer,
pointsize=&gt;integer, density=&gt;
geometry, stroke=&gt; color name,
strokewidth=&gt;integer, fill=&gt;color
name, undercolor=&gt;color name,
geometry=&gt;geometry, gravity=&gt;
{NorthWest, North, NorthEast,
West, Center, East, SouthWest,
South, SouthEast}, antialias=&gt;
{true, false}, x=&gt;integer, y=&gt;
integer, affine=&gt;array of float
values, translate=&gt;float, float,
scale=&gt;float, float, rotate=&gt;
float. skewX=&gt;float, skewY=&gt;
float, align=&gt;{Left, Center,
Right}, encoding=&gt;{UTF-8}</p></td>
<td><p>annotate an image
with text. See
QueryFontMetrics to
get font metrics
without rendering any
text.</p></td>
</tr>
<tr><td><p>Blur</p></td>
<td><p>geometry=&gt;geometry, radius=&gt;
double, sigma=&gt; double</p></td>
<td><p>blur the image with a
Gaussian operator of
the given radius and
standard deviation
(sigma).</p></td>
</tr>
<tr><td><p>Border</p></td>
<td><p>geometry=&gt;geometry, width=&gt;
integer, height=&gt; integer, fill=&gt;
color name</p></td>
<td><p>surround the image
with a border of
color</p></td>
</tr>
<tr><td><p>Channel</p></td>
<td><p>channel=&gt;{Red, Cyan, Green,
Magenta, Blue, Yellow, Opacity,
Black, Matte, All, Gray}</p></td>
<td><p>extract a channel
from the image</p></td>
</tr>
<tr><td><p>Charcoal</p></td>
<td><p>order=&gt;integer</p></td>
<td><p>simulate a charcoal
drawing</p></td>
</tr>
<tr><td><p>Chop</p></td>
<td><p>geometry=&gt;geometry, width=&gt;
integer, height=&gt; integer, x=&gt;
integer, y=&gt;integer</p></td>
<td><p>chop an image</p></td>
</tr>
<tr><td><p>Coalesce</p></td>
<td></td>
<td><p>merge a sequence of
images</p></td>
</tr>
<tr><td><p>Clip</p></td>
<td></td>
<td><p>apply any clipping
path information as
an image clip mask.</p></td>
</tr>
<tr><td><p>ColorFloodfill</p></td>
<td><p>geometry=&gt;geometry, x=&gt;integer, y
=&gt;integer , fill=&gt;color name,
bordercolor=&gt; color name</p></td>
<td><p>changes the color
value of any pixel
that matches the
color of the target
pixel and is a
neighbor. If you
specify a border
color, the color
value is changed for
any neighbor pixel
that is not that
color.</p></td>
</tr>
<tr><td><p>Colorize</p></td>
<td><p>fill=&gt;color name, opacity=&gt;string</p></td>
<td><p>colorize the image
with the fill color</p></td>
</tr>
<tr><td><p>Comment</p></td>
<td><p>string</p></td>
<td><p>add a comment to your
image</p></td>
</tr>
<tr><td><p>Compare</p></td>
<td><p>image=&gt;image-handle</p></td>
<td><p>compare image to a
reference image</p></td>
</tr>
<tr><td><p>Composite</p></td>
<td><p>image=&gt;image-handle, compose=&gt;{
Over, In, Out, Atop, Xor, Plus,
Minus, Add, Subtract,
Difference, Multiply, Bumpmap,
Copy, CopyRed, CopyGreen,
CopyBlue, CopyOpacity,
Clear, Dissolve, Displace,
Modulate, Threshold, No, Darken,
Lighten, Hue, Saturate,
Colorize, Luminize, Screen,
Overlay, CopyCyan, CopyMagenta,
CopyYellow, CopyBlack, Divide,
HardLight},
mask=&gt;
image-handle, geometry=&gt;geometry,
x=&gt;integer, y=&gt;integer, gravity=&gt;
{NorthWest, North, NorthEast,
West, Center, East, SouthWest,
South, SouthEast}, opacity=&gt;
integer, tile=&gt;{True, False},
rotate=&gt;double, color=&gt;color name</p></td>
<td><p>composite one image
onto another</p></td>
</tr>
<tr><td><p>Contrast</p></td>
<td><p>sharpen=&gt;{True, False}</p></td>
<td><p>enhance or reduce the
image contrast</p></td>
</tr>
<tr><td><p>Convolve</p></td>
<td><p>coefficients=&gt;array of float
values</p></td>
<td><p>apply a convolution
kernel to the image.
Given a kernel order
, you would supply
order*order float
values (e.g. 3x3
implies 9 values).</p></td>
</tr>
<tr><td><p>Crop</p></td>
<td><p>geometry=&gt;geometry, width=&gt;
integer, height=&gt; integer, x=&gt;
integer, y=&gt;integer</p></td>
<td><p>crop an image</p></td>
</tr>
<tr><td><p>CycleColormap</p></td>
<td><p>amount=&gt;integer</p></td>
<td><p>displace image
colormap by amount</p></td>
</tr>
<tr><td><p>Deconstruct</p></td>
<td></td>
<td><p>break down an image
sequence into
constituent parts</p></td>
</tr>
<tr><td><p>Despeckle</p></td>
<td></td>
<td><p>reduce the speckles
within an image</p></td>
</tr>
<tr><td><p>Draw</p></td>
<td><p>primitive=&gt;{point, line,
rectangle, roundRectangle, arc,
ellipse, circle, polyline,
polygon, ,bezier, path, color,
matte, text, image, &#64;filename},
points=&gt;string , method=&gt;{Point,
Replace, Floodfill, FillToBorder,
Reset}, stroke=&gt; color name, fill
=&gt;color name, tile=&gt;image-handle,
strokewidth=&gt;float, antialias=&gt;
{true, false}, bordercolor=&gt;color
name, x=&gt; float, y=&gt;float, affine
=&gt;array of float values,
translate=&gt;float, float, scale=&gt;
float, float, rotate=&gt;float.
skewX=&gt;float, skewY=&gt; float</p></td>
<td><p>annotate an image
with one or more
graphic primitives</p></td>
</tr>
<tr><td><p>Edge</p></td>
<td><p>radius=&gt;double</p></td>
<td><p>enhance edges within
the image with a
convolution filter of
the given radius.</p></td>
</tr>
<tr><td><p>Emboss</p></td>
<td><p>geometry=&gt;geometry, radius=&gt;
double, sigma=&gt; double</p></td>
<td><p>emboss the image with
a convolution filter
of the given radius
and standard
deviation (sigma).</p></td>
</tr>
<tr><td><p>Enhance</p></td>
<td></td>
<td><p>apply a digital
filter to enhance a
noisy image</p></td>
</tr>
<tr><td><p>Equalize</p></td>
<td></td>
<td><p>perform histogram
equalization to the
image</p></td>
</tr>
<tr><td><p>Flatten</p></td>
<td></td>
<td><p>flatten a sequence of
images</p></td>
</tr>
<tr><td><p>Flip</p></td>
<td></td>
<td><p>create a mirror image
by reflecting the
image scanlines in
the vertical
direction</p></td>
</tr>
<tr><td><p>Flop</p></td>
<td></td>
<td><p>create a mirror image
by reflecting the
image scanlines in
the horizontal
direction</p></td>
</tr>
<tr><td><p>Frame</p></td>
<td><p>geometry=&gt;geometry, width=&gt;
integer, height=&gt; integer, inner
=&gt;integer, outer=&gt;integer, fill=&gt;
color name</p></td>
<td><p>surround the image
with an ornamental
border</p></td>
</tr>
<tr><td><p>Gamma</p></td>
<td><p>gamma=&gt;string, red=&gt;double, green
=&gt;double , blue=&gt;double</p></td>
<td><p>gamma correct the
image</p></td>
</tr>
<tr><td><p>Implode</p></td>
<td><p>amount=&gt;double</p></td>
<td><p>implode image pixels
about the center</p></td>
</tr>
<tr><td><p>Label</p></td>
<td><p>string</p></td>
<td><p>assign a label to an
image</p></td>
</tr>
<tr><td><p>Level</p></td>
<td><p>level=&gt;string, 'black-point'=&gt;
double, 'mid-point'=&gt;double,
'white-point'=&gt;double</p></td>
<td><p>adjust the level of
image contrast</p></td>
</tr>
<tr><td><p>Magnify</p></td>
<td></td>
<td><p>double the size of an
image</p></td>
</tr>
<tr><td><p>Map</p></td>
<td><p>image=&gt;image-handle, dither=&gt;
{True, False}</p></td>
<td><p>choose a particular
set of colors from
this image</p></td>
</tr>
<tr><td><p>MatteFloodfill</p></td>
<td><p>geometry=&gt;geometry, x=&gt;integer, y
=&gt;integer , matte=&gt;integer,
bordercolor=&gt;color name</p></td>
<td><p>changes the matte
value of any pixel
that matches the
color of the target
pixel and is a
neighbor. If you
specify a border
color, the matte
value is changed for
any neighbor pixel
that is not that
color.</p></td>
</tr>
<tr><td><p>MedianFilter</p></td>
<td><p>radius=&gt;double</p></td>
<td><p>replace each pixel
with the median
intensity pixel of a
neighborhood.</p></td>
</tr>
<tr><td><p>Minify</p></td>
<td></td>
<td><p>half the size of an
image</p></td>
</tr>
<tr><td><p>Modulate</p></td>
<td><p>brightness=&gt;double, saturation=&gt;
double, hue=&gt; double</p></td>
<td><p>vary the brightness,
saturation, and hue
of an image by the
specified percentage</p></td>
</tr>
<tr><td><p>MotionBlur</p></td>
<td><p>geometry=&gt;geometry, radius=&gt;
double, sigma=&gt; double, angle=&gt;
double</p></td>
<td><p>blur the image with a
Gaussian operator of
the given radius and
standard deviation
(sigma) at the given
angle to simulate the
effect of motion</p></td>
</tr>
<tr><td><p>Negate</p></td>
<td><p>gray=&gt;{True, False}</p></td>
<td><p>replace every pixel
with its
complementary color
(white becomes black,
yellow becomes blue,
etc.)</p></td>
</tr>
<tr><td><p>Normalize</p></td>
<td></td>
<td><p>transform image to
span the full range
of color values</p></td>
</tr>
<tr><td><p>OilPaint</p></td>
<td><p>radius=&gt;integer</p></td>
<td><p>simulate an oil
painting</p></td>
</tr>
<tr><td><p>Opaque</p></td>
<td><p>color=&gt;color name, fill=&gt; color
name</p></td>
<td><p>change this color to
the fill color within
the image</p></td>
</tr>
<tr><td><p>Quantize</p></td>
<td><p>colors=&gt;integer, colorspace=&gt;
{RGB, Gray, Transparent, OHTA,
XYZ, YCbCr, YIQ, YPbPr, YUV,
CMYK}, treedepth=&gt; integer,
dither=&gt;{True, False},
measure_error=&gt;{True, False},
global_colormap=&gt;{True, False}</p></td>
<td><p>preferred number of
colors in the image</p></td>
</tr>
<tr><td><p>Profile</p></td>
<td><p>name=&gt;{ICM, IPTC}, profile=&gt;blob</p></td>
<td><p>add or remove ICC or
IPTC image profile</p></td>
</tr>
<tr><td><p>Raise</p></td>
<td><p>geometry=&gt;geometry, width=&gt;
integer, height=&gt; integer, x=&gt;
integer, y=&gt;integer, raise=&gt;
{True, False}</p></td>
<td><p>lighten or darken
image edges to create
a 3-D effect</p></td>
</tr>
<tr><td><p>ReduceNoise</p></td>
<td><p>radius=&gt;double</p></td>
<td><p>reduce noise in the
image with a noise
peak elimination
filter</p></td>
</tr>
<tr><td><p>Resize</p></td>
<td><p>geometry=&gt;geometry, width=&gt;
integer, height=&gt; integer, filter
=&gt;{Point, Box, Triangle, Hermite,
Hanning, Hamming, Blackman,
Gaussian, Quadratic, Cubic,
Catrom, Mitchell, Lanczos,
Bessel, Sinc}, blur=&gt;double</p></td>
<td><p>scale image to
desired size. Specify
blur &gt; 1 for blurry
or &lt; 1 for sharp</p></td>
</tr>
<tr><td><p>Roll</p></td>
<td><p>geometry=&gt;geometry, x=&gt;integer, y
=&gt;integer</p></td>
<td><p>roll an image
vertically or
horizontally</p></td>
</tr>
<tr><td><p>Rotate</p></td>
<td><p>degrees=&gt;double, color=&gt;color
name</p></td>
<td><p>rotate an image</p></td>
</tr>
<tr><td><p>Sample</p></td>
<td><p>geometry=&gt;geometry, width=&gt;
integer, height=&gt; integer</p></td>
<td><p>scale image with
pixel sampling</p></td>
</tr>
<tr><td><p>Scale</p></td>
<td><p>geometry=&gt;geometry, width=&gt;
integer, height=&gt; integer</p></td>
<td><p>scale image to
desired size</p></td>
</tr>
<tr><td><p>Segment</p></td>
<td><p>colorspace=&gt;{RGB, Gray,
Transparent, OHTA, XYZ, YCbCr,
YCC, YIQ, YPbPr, YUV, CMYK},
verbose={True, False}, cluster=&gt;
double, smooth= double</p></td>
<td><p>segment an image by
analyzing the
histograms of the
color components and
identifying units
that are homogeneous</p></td>
</tr>
<tr><td><p>Shade</p></td>
<td><p>geometry=&gt;geometry, azimuth=&gt;
double, elevation=&gt; double, gray
=&gt;{true, false}</p></td>
<td><p>shade the image using
a distant light
source</p></td>
</tr>
<tr><td><p>Sharpen</p></td>
<td><p>geometry=&gt;geometry, radius=&gt;
double, sigma=&gt; double</p></td>
<td><p>sharpen the image
with a Gaussian
operator of the given
radius and standard
deviation (sigma).</p></td>
</tr>
<tr><td><p>Shave</p></td>
<td><p>geometry=&gt;geometry, width=&gt;
integer, height=&gt; integer</p></td>
<td><p>shave pixels from the
image edges</p></td>
</tr>
<tr><td><p>Shear</p></td>
<td><p>geometry=&gt;geometry, x=&gt;double, y
=&gt;double color=&gt;color name</p></td>
<td><p>shear the image along
the X or Y axis by a
positive or negative
shear angle</p></td>
</tr>
<tr><td><p>Signature</p></td>
<td></td>
<td><p>generate an SHA-256
message digest for
the image pixel
stream</p></td>
</tr>
<tr><td><p>Solarize</p></td>
<td><p>threshold=&gt;integer</p></td>
<td><p>negate all pixels
above the threshold
level</p></td>
</tr>
<tr><td><p>Spread</p></td>
<td><p>amount=&gt;integer</p></td>
<td><p>displace image pixels
by a random amount</p></td>
</tr>
<tr><td><p>Stereo</p></td>
<td><p>image=&gt;image-handle</p></td>
<td><p>composites two images
and produces a single
image that is the
composite of a left
and right image of a
stereo pair</p></td>
</tr>
<tr><td><p>Stegano</p></td>
<td><p>image=&gt;image-handle, offset=&gt;
integer</p></td>
<td><p>hide a digital
watermark within the
image</p></td>
</tr>
<tr><td><p>Swirl</p></td>
<td><p>degrees=&gt;double</p></td>
<td><p>swirl image pixels
about the center</p></td>
</tr>
<tr><td><p>Texture</p></td>
<td><p>texture=&gt;image-handle</p></td>
<td><p>name of texture to
tile onto the image
background</p></td>
</tr>
<tr><td><p>Threshold</p></td>
<td><p>threshold=&gt;string</p></td>
<td><p>threshold the image</p></td>
</tr>
<tr><td><p>Transparent</p></td>
<td><p>color=&gt;color name</p></td>
<td><p>make this color
transparent within
the image</p></td>
</tr>
<tr><td><p>Trim</p></td>
<td></td>
<td><p>remove edges that are
the background color
from the image</p></td>
</tr>
<tr><td><p>UnsharpMask</p></td>
<td><p>geometry=&gt;geometry, radius=&gt;
double, sigma=&gt; double, amount=&gt;
double, threshold=&gt;double</p></td>
<td><p>sharpen the image
with the unsharp mask
algorithm.</p></td>
</tr>
<tr><td><p>Wave</p></td>
<td><p>geometry=&gt;geometry, amplitude=&gt;
double, wavelength=&gt; double</p></td>
<td><p>alter an image along
a sine wave</p></td>
</tr>
</tbody>
</table>
<p>Note, that the geometry parameter is a short cut for the width and height
parameters (e.g. geometry=&gt;'106x80' is equivalent to width=&gt;106,
height=&gt;80).</p>
<p>You can specify &#64;filename in both Annotate() and Draw(). This reads the
text or graphic primitive instructions from a file on disk. For example,</p>
<pre class="literal-block">$image-&gt;Draw(fill=&gt;'red', primitive=&gt;'rectangle',
points=&gt;'20,20 100,100 40,40 200,200 60,60 300,300');</pre>
<p>Is equivalent to</p>
<pre class="literal-block">$image-&gt;Draw(fill=&gt;'red', primitive=&gt;'&#64;draw.txt');</pre>
<p>Where draw.txt is a file on disk that contains this:</p>
<pre class="literal-block">rectangle 20, 20 100, 100
rectangle 40, 40 200, 200
rectangle 60, 60 300, 300</pre>
<p>The text parameter for methods, Annotate(), Comment(), Draw(), and
Label() can include the image filename, type, width, height, or other
image attribute by embedding these special format characters:</p>
<pre class="literal-block">%b file size
%d comment
%d directory
%e filename extension
%f filename
%h height
%m magick
%p page number
%s scene number
%t top of filename
%w width
%x x resolution
%y y resolution
\n newline
\r carriage return</pre>
<p>For example,</p>
<pre class="literal-block">text=&gt;&quot;%m:%f %wx%h&quot;</pre>
<p>produces an annotation of MIFF:bird.miff 512x480 for an image titled
bird.miff and whose width is 512 and height is 480.</p>
<p>You can optionally add Image to any method name. For example, TrimImage()
is an alias for method Trim().</p>
<p>Most of the attributes listed above have an analog in convert. See the
documentation for a more detailed description of these attributes.</p>
</section>
<section id="set-an-image-attribute">
<h1><a class="toc-backref" href="#id10">Set an Image Attribute</a></h1>
<p>Use method Set() to set an image attribute. For example,</p>
<pre class="literal-block">$image-&gt;Set(dither=&gt;'True');
$image-&gt;[$x]-&gt;Set(delay=&gt;3);</pre>
<p>And here is a list of all the image attributes you can set:</p>
<table>
<caption>Image Attributes</caption>
<colgroup>
<col style="width: 23%" />
<col style="width: 51%" />
<col style="width: 27%" />
</colgroup>
<tbody>
<tr><td><p>Attribute</p></td>
<td><p>Values</p></td>
<td><p>Description</p></td>
</tr>
<tr><td><p>adjoin</p></td>
<td><p>{True, False}</p></td>
<td><p>join images into a
single multi-image
file</p></td>
</tr>
<tr><td><p>antialias</p></td>
<td><p>{True, False}</p></td>
<td><p>remove pixel
aliasing</p></td>
</tr>
<tr><td><p>authenticate</p></td>
<td><p>string</p></td>
<td><p>decrypt image with
this password.</p></td>
</tr>
<tr><td><p>background</p></td>
<td><p>color name</p></td>
<td><p>image background
color</p></td>
</tr>
<tr><td><p>blue-primary</p></td>
<td><p>x-value, y-value</p></td>
<td><p>chromaticity blue
primary point (e.g.
0.15, 0.06)</p></td>
</tr>
<tr><td><p>bordercolor</p></td>
<td><p>color name</p></td>
<td><p>set the image
border color</p></td>
</tr>
<tr><td><p>clip-mask</p></td>
<td><p>image</p></td>
<td><p>Associate a clip
mask with the
image.</p></td>
</tr>
<tr><td><p>colormap[i]</p></td>
<td><p>color name</p></td>
<td><p>color name (e.g.
red) or hex value
(e.g. #ccc) at
position i</p></td>
</tr>
<tr><td><p>colorspace</p></td>
<td><p>{RGB, CMYK}</p></td>
<td><p>type of colorspace</p></td>
</tr>
<tr><td><p>comment</p></td>
<td><p>string</p></td>
<td><p>Append to the image
comment.</p></td>
</tr>
<tr><td><p>compression</p></td>
<td><p>{None, BZip, Fax, Group4, JPEG,
LosslessJPEG, LZW, RLE, Zip, LZMA
JPEG2000, JBIG1, JBIG2}</p></td>
<td><p>type of image
compression</p></td>
</tr>
<tr><td><p>debug</p></td>
<td><p>{No, Configure, Annotate, Render,
Transform, Locale, Coder, X11,
Cache, Blob, Deprecate, User,
Resource, TemporaryFile,
Exception,All}</p></td>
<td><p>log copious
debugging
information  for
one or more event
types</p></td>
</tr>
<tr><td><p>delay</p></td>
<td><p>integer</p></td>
<td><p>this many 1/100ths
of a second must
expire before
displaying the next
image in a sequence</p></td>
</tr>
<tr><td><p>density</p></td>
<td><p>geometry</p></td>
<td><p>vertical and
horizontal
resolution in
pixels of the image</p></td>
</tr>
<tr><td><p>disk-limit</p></td>
<td><p>integer</p></td>
<td><p>set disk resource
limit in megabytes</p></td>
</tr>
<tr><td><p>dispose</p></td>
<td><p>{Undefined, None, Background,
Previous}</p></td>
<td><p>GIF disposal method</p></td>
</tr>
<tr><td><p>dither</p></td>
<td><p>{True, False}</p></td>
<td><p>apply error
diffusion to the
image</p></td>
</tr>
<tr><td><p>display</p></td>
<td><p>string</p></td>
<td><p>specifies the X
server to contact</p></td>
</tr>
<tr><td><p>endian</p></td>
<td><p>{Undefined, LSB, MSB, Native}</p></td>
<td><p>specifies the
ordering of bytes
in a multi-byte
word. MSB is
big-endian, LSB is
little-endian, and
Native is whatever
the current host
uses by default.</p></td>
</tr>
<tr><td><p>file</p></td>
<td><p>filehandle</p></td>
<td><p>set the image
filehandle</p></td>
</tr>
<tr><td><p>filename</p></td>
<td><p>string</p></td>
<td><p>set the image
filename</p></td>
</tr>
<tr><td><p>fill</p></td>
<td><p>color</p></td>
<td><p>The fill color
paints any areas
inside the outline
of drawn shape.</p></td>
</tr>
<tr><td><p>font</p></td>
<td><p>string</p></td>
<td><p>use this font when
annotating the
image with text</p></td>
</tr>
<tr><td><p>fuzz</p></td>
<td><p>integer</p></td>
<td><p>colors within this
distance are
considered equal</p></td>
</tr>
<tr><td><p>gamma</p></td>
<td><p>double</p></td>
<td><p>gamma level of the
image</p></td>
</tr>
<tr><td><p>Gravity</p></td>
<td><p>{Forget, NorthWest, North,
NorthEast, West, Center, East,
SouthWest, South, SouthEast}</p></td>
<td><p>type of image
gravity</p></td>
</tr>
<tr><td><p>green-primary</p></td>
<td><p>x-value, y-value</p></td>
<td><p>chromaticity green
primary point (e.g.
0.3, 0.6)</p></td>
</tr>
<tr><td><p>index[x, y]</p></td>
<td><p>string</p></td>
<td><p>colormap index at
position (x, y)</p></td>
</tr>
<tr><td><p>interlace</p></td>
<td><p>{None, Line, Plane, Partition}</p></td>
<td><p>the type of
interlacing scheme</p></td>
</tr>
<tr><td><p>iterations</p></td>
<td><p>integer</p></td>
<td><p>add Netscape loop
extension to your
GIF animation</p></td>
</tr>
<tr><td><p>label</p></td>
<td><p>string</p></td>
<td><p>Append to the image
label.</p></td>
</tr>
<tr><td><p>loop</p></td>
<td><p>integer</p></td>
<td><p>add Netscape loop
extension to your
GIF animation</p></td>
</tr>
<tr><td><p>magick</p></td>
<td><p>string</p></td>
<td><p>set the image
format</p></td>
</tr>
<tr><td><p>matte</p></td>
<td><p>{True, False}</p></td>
<td><p>True if the image
has transparency</p></td>
</tr>
<tr><td><p>mattecolor</p></td>
<td><p>color name</p></td>
<td><p>set the image matte
color</p></td>
</tr>
<tr><td><p>map-limit</p></td>
<td><p>integer</p></td>
<td><p>set map resource
limit in megabytes</p></td>
</tr>
<tr><td><p>memory-limit</p></td>
<td><p>integer</p></td>
<td><p>set memory resource
limit in megabytes</p></td>
</tr>
<tr><td><p>monochrome</p></td>
<td><p>{True, False}</p></td>
<td><p>transform the image
to black and white</p></td>
</tr>
<tr><td><p>page</p></td>
<td><p>{ Letter, Tabloid, Ledger, Legal,
Statement, Executive, A3, A4, A5,
B4, B5, Folio, Quarto, 10x14} or
geometry</p></td>
<td><p>preferred size and
location of an
image canvas</p></td>
</tr>
<tr><td><p>pixel[x, y]</p></td>
<td><p>string</p></td>
<td><p>hex value (e.g. #
ccc) at position (x
, y)</p></td>
</tr>
<tr><td><p>pointsize</p></td>
<td><p>integer</p></td>
<td><p>pointsize of the
Postscript or
TrueType font</p></td>
</tr>
<tr><td><p>preview</p></td>
<td><p>{ Rotate, Shear, Roll, Hue,
Saturation, Brightness, Gamma,
Spiff, Dull, Grayscale, Quantize,
Despeckle, ReduceNoise, AddNoise,
Sharpen, Blur, Threshold,
EdgeDetect, Spread, Solarize, Shade,
Raise, Segment, Swirl, Implode,
Wave, OilPaint, Charcoal,
JPEG}</p></td>
<td><p>type of preview for
the Preview image
format</p></td>
</tr>
<tr><td><p>quality</p></td>
<td><p>integer</p></td>
<td><p>JPEG/MIFF/PNG
compression level</p></td>
</tr>
<tr><td><p>red-primary</p></td>
<td><p>x-value, y-value</p></td>
<td><p>chromaticity red
primary point (e.g.
0.64, 0.33)</p></td>
</tr>
<tr><td><p>rendering-intent</p></td>
<td><p>{Undefined, Saturation, Perceptual,
Absolute, Relative}</p></td>
<td><p>the type of
rendering intent</p></td>
</tr>
<tr><td><p>sampling-factor</p></td>
<td><p>geometry</p></td>
<td><p>horizontal and
vertical sampling
factor</p></td>
</tr>
<tr><td><p>scene</p></td>
<td><p>integer</p></td>
<td><p>image scene number</p></td>
</tr>
<tr><td><p>subimage</p></td>
<td><p>integer</p></td>
<td><p>subimage of an
image sequence</p></td>
</tr>
<tr><td><p>subrange</p></td>
<td><p>integer</p></td>
<td><p>number of images
relative to the
base image</p></td>
</tr>
<tr><td><p>server</p></td>
<td><p>string</p></td>
<td><p>specifies the X
server to contact</p></td>
</tr>
<tr><td><p>size</p></td>
<td><p>string</p></td>
<td><p>width and height of
a raw image</p></td>
</tr>
<tr><td><p>stroke</p></td>
<td><p>color</p></td>
<td><p>The stroke color
paints along the
outline of a shape.</p></td>
</tr>
<tr><td><p>tile</p></td>
<td><p>string</p></td>
<td><p>tile name</p></td>
</tr>
<tr><td><p>texture</p></td>
<td><p>string</p></td>
<td><p>name of texture to
tile onto the image
background</p></td>
</tr>
<tr><td><p>type</p></td>
<td><p>{Bilevel, Grayscale, GrayscaleMatte,
Palette, PaletteMatte, TrueColor,
TrueColorMatte, ColorSeparation,
ColorSeparationMatte, Optimize }</p></td>
<td><p>image type</p></td>
</tr>
<tr><td><p>units</p></td>
<td><p>{ Undefined, PixelsPerInch,
PixelsPerCentimeters}</p></td>
<td><p>units of image
resolution</p></td>
</tr>
<tr><td><p>verbose</p></td>
<td><p>{True, False}</p></td>
<td><p>print detailed
information about
the image</p></td>
</tr>
<tr><td><p>virtual-pixel</p></td>
<td><p>{Constant, Edge, Mirror, Tile}</p></td>
<td><p>the virtual pixel
method</p></td>
</tr>
<tr><td><p>white-point</p></td>
<td><p>x-value, y-value</p></td>
<td><p>chromaticity white
point (e.g. 0.3127,
0.329)</p></td>
</tr>
</tbody>
</table>
<p>Note, that the geometry parameter is a short cut for the width and height
parameters (e.g. geometry=&gt;'106x80' is equivalent to width=&gt;106, height=&gt;
80).</p>
<p>SetAttribute() is an alias for method Set().</p>
<p>Most of the attributes listed above have an analog in gm convert. See the
gm documentation for a more detailed description of these attributes.</p>
</section>
<section id="get-an-image-attribute">
<h1><a class="toc-backref" href="#id11">Get an Image Attribute</a></h1>
<p>Use method Get() to get an image attribute. For example,</p>
<pre class="literal-block">($a, $b, $c) = $image-&gt;Get('colorspace', 'magick', 'adjoin');
$width = $image-&gt;[3]-&gt;Get('columns');</pre>
<p>In addition to all the attributes listed in Set an Image Attribute , you
can get these additional attributes:</p>
<table>
<caption>Image Attributes</caption>
<colgroup>
<col style="width: 18%" />
<col style="width: 14%" />
<col style="width: 68%" />
</colgroup>
<tbody>
<tr><td><p>Attribute</p></td>
<td><p>Values</p></td>
<td><p>Description</p></td>
</tr>
<tr><td><p>base-columns</p></td>
<td><p>integer</p></td>
<td><p>base image width (before transformations)</p></td>
</tr>
<tr><td><p>base-filename</p></td>
<td><p>string</p></td>
<td><p>base image filename (before transformations)</p></td>
</tr>
<tr><td><p>base-rows</p></td>
<td><p>integer</p></td>
<td><p>base image height (before transformations)</p></td>
</tr>
<tr><td><p>class</p></td>
<td><p>{Direct,
Pseudo}</p></td>
<td><p>image class</p></td>
</tr>
<tr><td><p>colors</p></td>
<td><p>integer</p></td>
<td><p>number of unique colors in the image</p></td>
</tr>
<tr><td><p>comment</p></td>
<td><p>string</p></td>
<td><p>image comment</p></td>
</tr>
<tr><td><p>columns</p></td>
<td><p>integer</p></td>
<td><p>image width</p></td>
</tr>
<tr><td><p>depth</p></td>
<td><p>integer</p></td>
<td><p>image depth</p></td>
</tr>
<tr><td><p>directory</p></td>
<td><p>string</p></td>
<td><p>tile names from within an image montage</p></td>
</tr>
<tr><td><p>error</p></td>
<td><p>double</p></td>
<td><p>the mean error per pixel computed with methods
Compare() or Quantize()</p></td>
</tr>
<tr><td><p>filesize</p></td>
<td><p>integer</p></td>
<td><p>number of bytes of the image on disk</p></td>
</tr>
<tr><td><p>format</p></td>
<td><p>string</p></td>
<td><p>get the descriptive image format</p></td>
</tr>
<tr><td><p>geometry</p></td>
<td><p>string</p></td>
<td><p>image geometry</p></td>
</tr>
<tr><td><p>height</p></td>
<td><p>integer</p></td>
<td><p>the number of rows or height of an image</p></td>
</tr>
<tr><td><p>id</p></td>
<td><p>integer</p></td>
<td><p>GraphicsMagick registry id</p></td>
</tr>
<tr><td><p>label</p></td>
<td><p>string</p></td>
<td><p>image label</p></td>
</tr>
<tr><td><p>maximum-error</p></td>
<td><p>double</p></td>
<td><p>the normalized max error per pixel computed with
methods Compare() or Quantize()</p></td>
</tr>
<tr><td><p>mean-error</p></td>
<td><p>double</p></td>
<td><p>the normalized mean error per pixel computed
with methods Compare() or Quantize()</p></td>
</tr>
<tr><td><p>montage</p></td>
<td><p>geometry</p></td>
<td><p>tile size and offset within an image montage</p></td>
</tr>
<tr><td><p>rows</p></td>
<td><p>integer</p></td>
<td><p>the number of rows or height of an image</p></td>
</tr>
<tr><td><p>signature</p></td>
<td><p>string</p></td>
<td><p>SHA-256 message digest associated with the image
pixel stream</p></td>
</tr>
<tr><td><p>taint</p></td>
<td><p>{True,
False}</p></td>
<td><p>True if the image has been modified</p></td>
</tr>
<tr><td><p>width</p></td>
<td><p>integer</p></td>
<td><p>the number of columns or width of an image</p></td>
</tr>
<tr><td><p>x-resolution</p></td>
<td><p>integer</p></td>
<td><p>x resolution of the image</p></td>
</tr>
<tr><td><p>y-resolution</p></td>
<td><p>integer</p></td>
<td><p>y resolution of the image</p></td>
</tr>
</tbody>
</table>
<p>GetAttribute() is an alias for method Get().</p>
<p>Most of the attributes listed above have an analog in convert. See the
documentation for a more detailed description of these attributes.</p>
</section>
<section id="create-an-image-montage">
<h1><a class="toc-backref" href="#id12">Create an Image Montage</a></h1>
<p>Use method Montage() to create a composite image by combining several
separate images. The images are tiled on the composite image with the
name of the image optionally appearing just below the individual tile.
For example,</p>
<pre class="literal-block">$image-&gt;Montage(geometry=&gt;'160x160', tile=&gt;'2x2', texture=&gt;'granite:');</pre>
<p>And here is a list of Montage() parameters you can set:</p>
<table>
<caption>Montage Parameters</caption>
<colgroup>
<col style="width: 15%" />
<col style="width: 52%" />
<col style="width: 32%" />
</colgroup>
<tbody>
<tr><td><p>Parameter</p></td>
<td><p>Values</p></td>
<td><p>Description</p></td>
</tr>
<tr><td><p>background</p></td>
<td><p>color name</p></td>
<td><p>background color name</p></td>
</tr>
<tr><td><p>borderwidth</p></td>
<td><p>integer</p></td>
<td><p>image border width</p></td>
</tr>
<tr><td><p>compose</p></td>
<td><p>{Over, In, Out, Atop, Xor, Plus,
Minus, Add, Subtract, Difference,
Bumpmap, Copy, Mask, Dissolve, Clear,
Displace}</p></td>
<td><p>composite operator</p></td>
</tr>
<tr><td><p>filename</p></td>
<td><p>string</p></td>
<td><p>name of montage image</p></td>
</tr>
<tr><td><p>fill</p></td>
<td><p>color name</p></td>
<td><p>fill color for
annotations</p></td>
</tr>
<tr><td><p>font</p></td>
<td><p>string</p></td>
<td><p>X11 font name</p></td>
</tr>
<tr><td><p>frame</p></td>
<td><p>geometry</p></td>
<td><p>surround the image with
an ornamental border</p></td>
</tr>
<tr><td><p>geometry</p></td>
<td><p>geometry</p></td>
<td><p>preferred tile and
border size of each
tile of the composite
image</p></td>
</tr>
<tr><td><p>gravity</p></td>
<td><p>{NorthWest, North, NorthEast, West,
Center, East, SouthWest, South,
SouthEast}</p></td>
<td><p>direction image
gravitates to within a
tile</p></td>
</tr>
<tr><td><p>ICM</p></td>
<td><p>blob</p></td>
<td><p>color information
profile</p></td>
</tr>
<tr><td><p>IPTC</p></td>
<td><p>blob</p></td>
<td><p>newswire information
profile</p></td>
</tr>
<tr><td><p>label</p></td>
<td><p>string</p></td>
<td><p>assign a label to an
image</p></td>
</tr>
<tr><td><p>mode</p></td>
<td><p>{Frame, Unframe, Concatenate}</p></td>
<td><p>thumbnail framing
options</p></td>
</tr>
<tr><td><p>pointsize</p></td>
<td><p>integer</p></td>
<td><p>pointsize of the
Postscript or TrueType
font</p></td>
</tr>
<tr><td><p>shadow</p></td>
<td><p>{True, False}</p></td>
<td><p>add a shadow beneath a
tile to simulate depth</p></td>
</tr>
<tr><td><p>stroke</p></td>
<td><p>color name</p></td>
<td><p>stroke color for
annotations</p></td>
</tr>
<tr><td><p>texture</p></td>
<td><p>string</p></td>
<td><p>name of texture to tile
onto the image
background</p></td>
</tr>
<tr><td><p>tile</p></td>
<td><p>geometry</p></td>
<td><p>number of tiles per row
and column</p></td>
</tr>
<tr><td><p>title</p></td>
<td><p>string</p></td>
<td><p>assign a title to the
image montage</p></td>
</tr>
<tr><td><p>transparent</p></td>
<td><p>string</p></td>
<td><p>make this color
transparent within the
image</p></td>
</tr>
</tbody>
</table>
<p>Note, that the geometry parameter is a short cut for the width and height
parameters (e.g. geometry=&gt;'106x80' is equivalent to width=&gt;106, height=&gt;
80).</p>
<p>MontageImage() is an alias for method Montage().</p>
<p>Most of the attributes listed above have an analog in montage. See the
documentation for a more detailed description of these attributes.</p>
</section>
<section id="working-with-blobs">
<h1><a class="toc-backref" href="#id13">Working with Blobs</a></h1>
<p>A blob contains data that directly represent a particular image format in
memory instead of on disk. PerlMagick supports blobs in any of these
image formats and provides methods to convert a blob to or from a
particular image format.</p>
<table>
<caption>Blob Methods</caption>
<colgroup>
<col style="width: 16%" />
<col style="width: 14%" />
<col style="width: 34%" />
<col style="width: 36%" />
</colgroup>
<tbody>
<tr><td><p>Method</p></td>
<td><p>Parameters</p></td>
<td><p>Return Value</p></td>
<td><p>Description</p></td>
</tr>
<tr><td><p>ImageToBlob</p></td>
<td><p>any image
attribute</p></td>
<td><p>an array of image data
in the respective image
format</p></td>
<td><p>convert an image or image
sequence to an array of
blobs</p></td>
</tr>
<tr><td><p>BlobToImage</p></td>
<td><p>one or
more blobs</p></td>
<td><p>the number of blobs
converted to an image</p></td>
<td><p>convert one or more blobs
to an image</p></td>
</tr>
</tbody>
</table>
<p>ImageToBlob() returns the image data in their respective formats. You can
then print it, save it to an ODBC database, write it to a file, or pipe
it to a display program:</p>
<pre class="literal-block">&#64;blobs = $image-&gt;ImageToBlob();
open(DISPLAY,&quot;| display -&quot;) || die;
binmode DISPLAY;
print DISPLAY $blobs[0];
close DISPLAY;</pre>
<p>Method BlobToImage() returns an image or image sequence converted from
the supplied blob:</p>
<pre class="literal-block">&#64;blob=$db-&gt;GetImage();
$image=Graphics::Magick-&gt;new(magick=&gt;'jpg');
$image-&gt;BlobToImage(&#64;blob);</pre>
</section>
<section id="miscellaneous-methods">
<h1><a class="toc-backref" href="#id14">Miscellaneous Methods</a></h1>
<p>The Append() method append a set of images. For example,</p>
<pre class="literal-block">$p = $image-&gt;Append(stack=&gt;{true,false});</pre>
<p>appends all the images associated with object $image. By default, images
are stacked left-to-right. Set stack to True to stack them top-to-bottom.</p>
<p>The Average() method averages a set of images. For example,</p>
<pre class="literal-block">$p = $image-&gt;Average();</pre>
<p>averages all the images associated with object $image.</p>
<p>The Clone() method copies a set of images. For example,</p>
<pre class="literal-block">$p = $image-&gt;Clone();</pre>
<p>copies all the images from object $q to $p. You can use this method for
single or multi-image sequences.</p>
<p>The Morph() method morphs a set of images. Both the image pixels and size
are linearly interpolated to give the appearance of a meta-morphosis from
one image to the next:</p>
<pre class="literal-block">$p = $image-&gt;Morph(frames=&gt;integer);</pre>
<p>where frames is the number of in-between images to generate. The default
is 1.</p>
<p>Mosaic() creates an mosaic from an image sequence.</p>
<p>Method Mogrify() is a single entry point for the image manipulation
methods (Manipulate an Image). The parameters are the name of a method
followed by any parameters the method may require. For example, these
calls are equivalent:</p>
<pre class="literal-block">$image-&gt;Crop('340x256+0+0');
$image-&gt;Mogrify('crop', '340x256+0+0');</pre>
<p>Method MogrifyRegion() applies a transform to a region of the image. It
is similar to Mogrify() but begins with the region geometry. For example,
suppose you want to brighten a 100x100 region of your image at location
(40, 50):</p>
<pre class="literal-block">$image-&gt;MogrifyRegion('100x100+40+50', 'modulate', brightness=&gt;50);</pre>
<p>Ping() is a convenience method that returns information about an image
without having to read the image into memory. It returns the width,
height, file size in bytes, and the file format of the image. You can
specify more than one filename but only one filehandle:</p>
<pre class="literal-block">($width, $height, $size, $format) = $image-&gt;Ping('logo.png');
($width, $height, $size, $format) = $image-&gt;Ping(file=&gt;\*IMAGE);
($width, $height, $size, $format) = $image-&gt;Ping(blob=&gt;&#64;blob);</pre>
<p>This is a more efficient and less memory intensive way to query if an
image exists and what its characteristics are.</p>
<p>To have full control over text positioning you need font metric
information. Use</p>
<pre class="literal-block">($x_ppem, $y_ppem, $ascender, $descender, $width, $height, $max_advance) =
$image-&gt;QueryFontMetrics(parameters);

Where parameters is any parameter of the Annotate method.  The
'text' parameter must be specified since there can be no default for
the text to render. The return values are

* character width
* character height
* ascender
* descender
* text width
* text height
* maximum horizontal advance</pre>
<p>Call QueryColor() with no parameters to return a list of known colors
names or specify one or more color names to get these attributes: red,
green, blue, and opacity value.</p>
<pre class="literal-block">&#64;colors = $image-&gt;QueryColor();
($red, $green, $blue, $opacity) = $image-&gt;QueryColor('cyan');
($red, $green, $blue, $opacity) = $image-&gt;QueryColor('#716bae');</pre>
<p>QueryColorname() accepts a color value and returns its respective name or
hex value;</p>
<pre class="literal-block">$name = $image-&gt;QueryColorname('rgba(80,60,0,0)');</pre>
<p>Call QueryFont() with no parameters to return a list of known fonts or
specify one or more font names to get these attributes: font name,
description, family, style, stretch, weight, encoding, foundry, format,
metrics, and glyphs values.</p>
<pre class="literal-block">&#64;fonts = $image-&gt;QueryFont();
$weight = ($image-&gt;QueryFont('Helvetica'))[5];</pre>
<p>Call QueryFormat() with no parameters to return a list of known image
formats or specify one or more format names to get these attributes:
adjoin, blob support, raw, decoder, encoder, description, and module.</p>
<pre class="literal-block">&#64;formats = $image-&gt;QueryFormat();
($adjoin, $blob_support, $raw, $decoder, $encoder, $description, $module) = $image-&gt;QueryFormat('gif');</pre>
<p>Use RemoteCommand() to send a command to an already running display or
animate application. The only parameter is the name of the image file to
display or animate.</p>
<p>Finally, the Transform() method accepts a fully-qualified geometry
specification for cropping or resizing one or more images. For example,</p>
<pre class="literal-block">$p = $image-&gt;Transform(crop=&gt;'100x100');</pre>
<p>You can optionally add Image to any method name above. For example,
PingImage() is an alias for method Ping().</p>
</section>
<section id="handling-errors">
<h1><a class="toc-backref" href="#id15">Handling Errors</a></h1>
<p>All PerlMagick methods return an undefined string context upon success. If
any problems occur, the error is returned as a string with an embedded
numeric status code. A status code less than 400 is a warning. This means
that the operation did not complete but was recoverable to some degree. A
numeric code greater or equal to 400 is an error and indicates the
operation failed completely. Here is how errors are returned for the
different methods:</p>
<blockquote>
<ul>
<li><p>Methods which return a number (e.g. Read(), Write()):</p>
<pre class="literal-block">$status = $image-&gt;Read(...);
warn &quot;$status&quot; if &quot;$status&quot;; # print the error message
$status =~ /(\d+)/;
print $1; # print the error number
print 0+$status; # print the number of images read</pre>
</li>
<li><p>Methods which operate on an image (e.g. Resize(), Crop()):</p>
<pre class="literal-block">$status = $image-&gt;Crop(...);
warn &quot;$status&quot; if &quot;$status&quot;; # print the error message
$status =~ /(\d+)/;
print $1; # print the error number</pre>
</li>
<li><p>Methods which return images (Average(), Montage(), Clone()) should be
checked for errors this way:</p>
<pre class="literal-block">$status = $image-&gt;Montage(...);
warn &quot;$status&quot; if !ref($status); # print the error message
$status =~ /(\d+)/;
print $1; # print the error number</pre>
</li>
</ul>
</blockquote>
<p>Here is an example error message:</p>
<pre class="literal-block">Error 400: Memory allocation failed</pre>
<p>Below is a list of error and warning codes:</p>
<table>
<caption>Error and Warning Codes</caption>
<colgroup>
<col style="width: 6%" />
<col style="width: 31%" />
<col style="width: 63%" />
</colgroup>
<tbody>
<tr><td><p>Code</p></td>
<td><p>Mnemonic</p></td>
<td><p>Description</p></td>
</tr>
<tr><td><p>0</p></td>
<td><p>Success</p></td>
<td><p>method completed without an error or warning</p></td>
</tr>
<tr><td><p>300</p></td>
<td><p>ResourceLimitWarning</p></td>
<td><p>a program resource is exhausted (e.g. not
enough memory)</p></td>
</tr>
<tr><td><p>305</p></td>
<td><p>TypeWarning</p></td>
<td><p>A font is unavailable; a substitution may
have occurred</p></td>
</tr>
<tr><td><p>310</p></td>
<td><p>OptionWarning</p></td>
<td><p>a command-line option was malformed</p></td>
</tr>
<tr><td><p>315</p></td>
<td><p>DelegateWarning</p></td>
<td><p>an GraphicsMagick delegate returned a warning</p></td>
</tr>
<tr><td><p>320</p></td>
<td><p>MissingDelegateWarning</p></td>
<td><p>the image type can not be read or written
because the appropriate Delegate is missing</p></td>
</tr>
<tr><td><p>325</p></td>
<td><p>CorruptImageWarning</p></td>
<td><p>the image file may be corrupt</p></td>
</tr>
<tr><td><p>330</p></td>
<td><p>FileOpenWarning</p></td>
<td><p>the image file could not be opened</p></td>
</tr>
<tr><td><p>335</p></td>
<td><p>BlobWarning</p></td>
<td><p>a binary large object could not be allocated</p></td>
</tr>
<tr><td><p>340</p></td>
<td><p>StreamWarning</p></td>
<td><p>there was a problem reading or writing from a
stream</p></td>
</tr>
<tr><td><p>345</p></td>
<td><p>CacheWarning</p></td>
<td><p>pixels could not be saved to the pixel cache</p></td>
</tr>
<tr><td><p>350</p></td>
<td><p>CoderWarning</p></td>
<td><p>there was a problem with an image coder</p></td>
</tr>
<tr><td><p>355</p></td>
<td><p>ModuleWarning</p></td>
<td><p>there was a problem with an image module</p></td>
</tr>
<tr><td><p>360</p></td>
<td><p>DrawWarning</p></td>
<td><p>a drawing operation failed</p></td>
</tr>
<tr><td><p>365</p></td>
<td><p>ImageWarning</p></td>
<td><p>the operation could not complete due to an
incompatible image</p></td>
</tr>
<tr><td><p>380</p></td>
<td><p>XServerWarning</p></td>
<td><p>an X resource is unavailable</p></td>
</tr>
<tr><td><p>385</p></td>
<td><p>MonitorWarning</p></td>
<td><p>there was a problem with prgress monitor</p></td>
</tr>
<tr><td><p>390</p></td>
<td><p>RegistryWarning</p></td>
<td><p>there was a problem getting or setting the
registry</p></td>
</tr>
<tr><td><p>395</p></td>
<td><p>ConfigureWarning</p></td>
<td><p>there was a problem getting a configuration
file</p></td>
</tr>
<tr><td><p>400</p></td>
<td><p>ResourceLimitError</p></td>
<td><p>a program resource is exhausted (e.g. not
enough memory)</p></td>
</tr>
<tr><td><p>405</p></td>
<td><p>TypeError</p></td>
<td><p>A font is unavailable; a substitution may
have occurred</p></td>
</tr>
<tr><td><p>410</p></td>
<td><p>OptionError</p></td>
<td><p>a command-line option was malformed</p></td>
</tr>
<tr><td><p>415</p></td>
<td><p>DelegateError</p></td>
<td><p>an GraphicsMagick delegate returned a warning</p></td>
</tr>
<tr><td><p>420</p></td>
<td><p>MissingDelegateError</p></td>
<td><p>the image type can not be read or written
because the appropriate Delegate is missing</p></td>
</tr>
<tr><td><p>425</p></td>
<td><p>CorruptImageError</p></td>
<td><p>the image file may be corrupt</p></td>
</tr>
<tr><td><p>430</p></td>
<td><p>FileOpenError</p></td>
<td><p>the image file could not be opened</p></td>
</tr>
<tr><td><p>435</p></td>
<td><p>BlobError</p></td>
<td><p>a binary large object could not be allocated</p></td>
</tr>
<tr><td><p>440</p></td>
<td><p>StreamError</p></td>
<td><p>there was a problem reading or writing from a
stream</p></td>
</tr>
<tr><td><p>445</p></td>
<td><p>CacheError</p></td>
<td><p>pixels could not be saved to the pixel cache</p></td>
</tr>
<tr><td><p>450</p></td>
<td><p>CoderError</p></td>
<td><p>there was a problem with an image coder</p></td>
</tr>
<tr><td><p>455</p></td>
<td><p>ModuleError</p></td>
<td><p>there was a problem with an image module</p></td>
</tr>
<tr><td><p>460</p></td>
<td><p>DrawError</p></td>
<td><p>a drawing operation failed</p></td>
</tr>
<tr><td><p>465</p></td>
<td><p>ImageError</p></td>
<td><p>the operation could not complete due to an
incompatible image</p></td>
</tr>
<tr><td><p>480</p></td>
<td><p>XServerError</p></td>
<td><p>an X resource is unavailable</p></td>
</tr>
<tr><td><p>480</p></td>
<td><p>MonitorError</p></td>
<td><p>there was a progress monitor error</p></td>
</tr>
<tr><td><p>490</p></td>
<td><p>RegistryError</p></td>
<td><p>there was a problem getting or setting the
registry</p></td>
</tr>
<tr><td><p>495</p></td>
<td><p>ConfigureError</p></td>
<td><p>there was a problem getting a configuration
file</p></td>
</tr>
</tbody>
</table>
<p>The following illustrates how you can use a numeric status code:</p>
<pre class="literal-block">$status = $image-&gt;Read('rose.png');
$status =~ /(\d+)/;
die &quot;unable to continue&quot; if ($1 == ResourceLimitError);</pre>
</section>
</main>


<hr class="docutils">
<div class="document">
    <p><a href="Copyright.html">Copyright</a> © GraphicsMagick Group 2002-2025<!--SPONSOR_LOGO--></p>
</div>

</main>
</body>
</html>
